<?php

namespace falcon5\inc\Base;

use lucatume\DI52\ContainerException;

/**
 * Class Common
 * @package falcon5\inc\Base
 * @desc
 */
class Common
{
    const FC5_CLIENT_TYPE = 'wordpress';

    const FC5_LANGUAGE_EDIT_KEY = 'language_edit';

    const FC5_LANGUAGE_EDIT_TOKEN = 'token';

    const FC5_LANGUAGE_EDIT_SITE_ID = 'site_id';

    const FC5_TEXT_DOMAIN = 'falcon5_text_domain';

    const PLUGIN_VERSION = '1.0.0';

    const PLUGIN_ID = 'falcon5';

    const PLUGIN_NAME = 'Falcon5Translate';
    //["path"=>"page path","originalLanguage"=>"original_language","lang"=>'targe lang']
    const Fc5_TEANSLATION_START_HOOK = "fc5_translation_start";
    //["page"=>$path,"lang"=>$lang,"body"=>$body,"pageId"=>$pageId];
    const Fc5_TEANSLATION_COMPLETE_HOOK = "fc5_translation_complete";
    //["page"=>$path,"lang"=>$lang,"error"=>'gateway error mesg',"pageId"=>$pageId];
    const Fc5_TEANSLATION_FAILURE_HOOK = "fc5_translation_failure";

    const Fc5_TEANSLATION_COMPLETE_BODY_FILTER_HOOK = "fc5_translation_body";

    const LANG_PATTERN = 'af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-cn|zh-tw|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu|zh-tw|zh-cn';

    /**
     * 插件路径
     * @var string
     */
    public $plugin_path;

    /**
     * 插件URL
     * @var string
     */
    public $plugin_url;

    /**
     * 插件基本名称
     * @var string
     */
    public $plugin;

    /**
     * 构造函数
     */
    public function __construct() {
        $this->plugin_path = plugin_dir_path( dirname( __FILE__, 2 ) );
        $this->plugin_url = plugin_dir_url( dirname( __FILE__, 2 ) );
        $this->plugin = plugin_basename( dirname( __FILE__, 3 ) ) . '/' . self::PLUGIN_ID . '.php';
    }

    public static function getFc5AdminLoginUrl()
    {
        return Config::get('api.admin_login_url', falcon5_env('FC5_ADMIN_LOGIN_URL', ''));
    }

    /**
     * 获取Falcon5代理主机地址
     * @return string
     * @throws ContainerException
     */
    public static function getFc5ProxyHost()
    {
        return Config::get('api.proxy_host', falcon5_env('FC5_ADMIN_LOGIN_URL', ''));
    }
    /**
     * 获取Falcon5代理端口
     * @return string
     * @throws ContainerException
     */
    public static function getEngineProxyHost()
    {
        return Config::get('api.proxy_host', falcon5_env('FC5_PROXY_HOST', ''));
    }
    //FC5_PLATFORM_URL
    public static function getPlatformProxyHost()
    {
        return Config::get('api.platform_proxy_host', falcon5_env('FC5_PLATFORM_HOST', ''));
    }
    /**
     * 获取Falcon5认证用户名
     * @return string
     * @throws ContainerException
     */
    public static function getFc5AuthUsername()
    {
        return Config::get('api.auth_username', falcon5_env('FC5_AUTH_USERNAME', 'web'));
    }

    /**
     * 获取Falcon5认证密码
     * @return string
     * @throws ContainerException
     */
    public static function getFc5AuthPassword()
    {
        return Config::get('api.auth_password', falcon5_env('FC5_AUTH_PASSWORD', 'web_password'));
    }

    /**
     * 获取插件版本
     * @return string
     */
    public static function getPluginVersion()
    {
        return Config::get('plugin.version', self::PLUGIN_VERSION);
    }

    /**
     * 获取插件ID
     * @return string
     */
    public static function getPluginId()
    {
        return Config::get('plugin.id', self::PLUGIN_ID);
    }

    /**
     * 获取插件名称
     * @return string
     */
    public static function getPluginName()
    {
        return Config::get('plugin.name', self::PLUGIN_NAME);
    }

    /**
     * 获取文本域
     * @return string
     */
    public static function getTextDomain()
    {
        return Config::get('plugin.text_domain', self::FC5_TEXT_DOMAIN);
    }

    /**
     * 获取客户端类型
     * @return string
     */
    public static function getClientType()
    {
        return Config::get('plugin.client_type', self::FC5_CLIENT_TYPE);
    }

    /**
     * 获取语言编辑键
     * @return string
     */
    public static function getLanguageEditKey()
    {
        return Config::get('language.edit_key', self::FC5_LANGUAGE_EDIT_KEY);
    }

    /**
     * 获取语言编辑token
     * @return string
     */
    public static function getLanguageEditToken()
    {
        return Config::get('language.edit_token', self::FC5_LANGUAGE_EDIT_TOKEN);
    }

    /**
     * 获取语言编辑站点id
     * @return string
     */
    public static function getLanguageEditSiteId()
    {
        return Config::get('language.edit_site_id', self::FC5_LANGUAGE_EDIT_SITE_ID);
    }

    /**
     * 获取语言模式
     * @return string
     */
    public static function getLanguagePattern()
    {
        return Config::get('language.pattern', self::LANG_PATTERN)??Config::get('language.pattern', strtolower(self::LANG_PATTERN));
    }
}